Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase the 252 per-block transaction limit #273

Merged
merged 3 commits into from
Jun 4, 2020

Conversation

LarryRuane
Copy link
Collaborator

The darksidewalletd code has a restriction that a block can have at most 252 transactions. This is because the number of transactions in a block is encoded as a variable integer (aka compact integer), and the serialization of 253 or greater requires more than one byte, so it's a little complex and messy, so we haven't bothered. But this doesn't allow us to stress-test the lightwalletd and the wallets under the condition that there are more than 252 transactions in a block. Merging this PR will allow #267 to proceed (creating actual tests). This PR also adds a bit more error detection to block parsing.

I tested this manually:

# start darksidewalletd
curl -s https://raw.githubusercontent.com/zcash-hackworks/darksidewalletd-test-data/master/transactions/t-shielded-spend.txt >t-shielded-spend.txt
mkdir blocks
for i in {1..253};do cat t-shielded-spend.txt >>blocks/1000.txt;done
go run testtools/genblocks/main.go >block-list # without this PR, this will fail
utils/submitblocks.sh 1000 block-list

Then verify that there are 253 transactions in this block (the last "index" should be "253"):

grpcurl -plaintext -d '{"height":1000}' localhost:9067 cash.z.wallet.sdk.rpc.CompactTxStreamer/GetBlock

Probably good to try the same with 254 and 255, to explore the edge cases.

@LarryRuane LarryRuane self-assigned this May 28, 2020
@LarryRuane LarryRuane requested a review from defuse June 2, 2020 16:51
@LarryRuane LarryRuane force-pushed the 2020-05-28-darkside-allow-many-tx branch from 6653a43 to 13381f1 Compare June 2, 2020 23:14
@LarryRuane LarryRuane force-pushed the 2020-05-28-darkside-allow-many-tx branch from 13381f1 to 8c48908 Compare June 3, 2020 05:16
Copy link
Collaborator Author

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a few explanatory comments.


if i < txCount {
return nil, errors.New("parsing block transactions: not enough data")
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, if the number of transactions actually in the block was less than the txCount (variable-length integer) in the block, the error would be silently ignored. Note that it's okay for there to be extra data, because it gets returned (below). In general, this parsing code allows sequences of blocks concatenated together, but we don't currently depend on that. The caller should check that no data remains.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The caller should check that no data remains." should be mentioned in a comment above the function

}, {
"df2b03619d441ce3d347e9278d87618e975079d0e235dfb3b3d8271510f707aa",
"8d2593edfc328fa637b4ac91c7d569ee922bb9a6fda7cea230e92deb3ae4b634",
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simpler than the old code; the old code "knew" that there were 4 blocks containing 1, 1, 2, 2 transactions respectively. So looping over the blocks, and for each block looping over its transactions, happens to amount to exactly 6 transactions The new code specifically lists the txids in each block. The reason for this change is not just to simplify, it's that now the blocks will gain more transactions as the test runs (repeats of the one or 2 that it already has, see below).

if numTransactions < 253 {
fmt.Printf("%02x", numTransactions)
} else {
fmt.Printf("%02x%02x%02x", 253, numTransactions%256, numTransactions/256)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using %02x seems a little simpler than hex.EncodeToString(), but the effect is the same. It's important to get the endianness correct here, the least-significant digit comes first (little-endian).

Copy link
Collaborator

@defuse defuse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK with one minor comment


if i < txCount {
return nil, errors.New("parsing block transactions: not enough data")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The caller should check that no data remains." should be mentioned in a comment above the function

@LarryRuane LarryRuane merged commit faca1ec into master Jun 4, 2020
@LarryRuane LarryRuane deleted the 2020-05-28-darkside-allow-many-tx branch June 4, 2020 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants